package com.ljx.recruitment.user.typehandler;

import cn.hutool.json.JSONUtil;
import com.ljx.recruitment.user.typehandler.details.ThemeDetails;
import com.ljx.recruitment.user.typehandler.details.ThemeDetails;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-10-31  10:33
 */
@MappedTypes(ThemeDetails.class)
public class TenantThemeTypeHandler extends BaseTypeHandler<ThemeDetails> {

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, ThemeDetails Themes, JdbcType jdbcType) throws SQLException {
        preparedStatement.setString(i, JSONUtil.toJsonStr(Themes));
    }

    @Override
    public ThemeDetails getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return JSONUtil.toBean(resultSet.getString(s), ThemeDetails.class);
    }

    @Override
    public ThemeDetails getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return JSONUtil.toBean(resultSet.getString(i), ThemeDetails.class);
    }

    @Override
    public ThemeDetails getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return JSONUtil.toBean(callableStatement.getString(i), ThemeDetails.class);
    }
}